import time

import allure


class Keywords:
    # __init__作用：只要用Keywords里面的任何一个方法，都需要给个浏览器
    def __init__(self, driver):
        self.driver = driver

    # 访问
    def open_url(self, **kwargs):
        self.driver.get(kwargs['text'])

    # 获取定位元素
    def on_input(self, **kwargs):
        self.driver.find_element(kwargs['by'], kwargs['locator']).send_keys(kwargs['text'])

    # 点击
    def on_click(self, **kwargs):
        self.driver.find_element(kwargs['by'], kwargs['locator']).click()

    def wait(self, **kwargs):
        self.driver.implicitly_wait(kwargs['text'])

    # 截图
    def screenshot(self, **kwargs):
        # self.driver.save_screenshot(kwargs['path'])
        allure.attach(self.driver.get_screenshot_as_png(), name=time.time(), attachment_type=allure.attachment_type.PNG)

    # 上传
    def upload(self, **kwargs):
        # self.driver.find_element(kwargs['by'], kwargs['locator']).send_keys(kwargs['path'])
        pass
